package com.baizhi.springboot.service.impl;

import com.baizhi.springboot.dao.LabelDao;
import com.baizhi.springboot.entity.Label;
import com.baizhi.springboot.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class LabelServiceImpl implements LabelService {
    @Autowired
    private LabelDao labelDao;

    @Override
    public Map selectLabelByPage(Integer page, Integer limit) {
        Integer offset=(page-1)*limit;
        List<Label> labels = labelDao.selectLabelByPage(offset, limit);
        Integer count = labelDao.selectCount();
        /* "code": 0,
          "msg": "",
          "count": 1000,
          "data": [{}, {}]*/
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", labels);
        return map;
    }

    @Override
    public void insertLabel(Label label) {
        labelDao.insertLabel(label);
    }

    @Override
    public void updateLabel(Label label) {
        labelDao.updateLabel(label);
    }

    @Override
    public Label selectOneLabel(Integer id) {
        return labelDao.selectOneLabel(id);
    }

    @Override
    public void deleteLabel(Integer id) {
        labelDao.deleteLabel(id);
    }
}
